import Vue from "vue"
import router from "./router"
import store from "./store"
import VueMeta from "vue-meta"
import Element from "element-ui"
import VueI18n from 'vue-i18n'
import ZhCn from './assets/languages/zh-cn.js'
import EnUs from './assets/languages/en-us.js'
import Cookies from 'js-cookie'

Vue.use(VueI18n);
let _lang = Cookies.get('website_lang') || 'zh-cn';
console.log('_lang====>', _lang)
const i18n = new VueI18n({
    locale: _lang, // 将要切换的语言，可以通过url拼的参数获取，用户行为select选择获取，本地manifest配置获取等，根据场景动态获取
    messages: {
        'en-us': EnUs,  // 本地资源文件，我这里配2个语言，中文&英文，src下根据个人情况放置
        'zh-cn': ZhCn
    }
});



import {
  Message
} from 'element-ui'

let messageInstance = null;
const overrideMessage = (options) => {
    if(messageInstance) {
        messageInstance.close()
    }
    messageInstance = Message(options)
}
['error','success','info','warning'].forEach(type => {
    overrideMessage[type] = options => {
        if(typeof options === 'string') {
            options = {
                message:options
            }
        }
        options.type = type
        return overrideMessage(options)
    }
})
Vue.use(Element)
Vue.prototype.$message = overrideMessage;

import scroll from 'vue-seamless-scroll'

import "element-ui/lib/theme-chalk/index.css"
import "./assets/styles/main.scss"
import "./assets/styles/element-variables.scss"

import VideoPlayer from "vue-video-player"
import "video.js/dist/video-js.css"

import App from "./App.vue"

import Util from "./utils/util"
import Lang from "./utils/lang.js"
import Config from "./utils/config.js"

Vue.prototype.$store = store //挂在vue
Vue.config.productionTip = false

// 常用工具函数
Vue.prototype.$util = Util
Vue.prototype.$img = Util.img
Vue.prototype.$timeStampTurnTime = Util.timeStampTurnTime
Vue.prototype.$copy = Util.copy
window.util = Util
window.img = Util.img
window.timeStampTurnTime = Util.timeStampTurnTime
window.copy = Util.copy

// 返回上级方法
Vue.prototype.$back = function () {
    router.back();
}

// 语言包
Vue.prototype.$langConfig = Lang //语言包对象
Vue.prototype.$lang = Lang.lang //解析语言包
window.langConfig = Lang
window.lang = Lang.lang

Vue.prototype.$config = Config

Vue.use(VideoPlayer)
Vue.use(VueMeta)
Vue.use(scroll)

window.vue = new Vue({
    router,
    store,
    i18n,
    metaInfo() {
        return {
            title: store.getters.siteInfo.title || "NiuShop",
            meta: [
                { name: "title", content: store.getters.siteInfo.title || "NiuShop" },
                { name: "desc", content: store.getters.siteInfo.desc || "" },
                { name: "keywords", content: store.getters.siteInfo.keywords || "" }
            ]
        }
    },
    render: h => h(App)
}).$mount("#app")
